#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>


int compare(const void*p1, const void*p2)
{
	return *((int*)p1) - *((int*)p2);
}

void Swap(char* buf1, char* buf2, size_t width)
{
	int i = 0;
	char tmp = 0;
	for (i = 0; i < width; i++)
	{
		tmp = *buf1;
		*buf1 = *buf2;
		*buf2 = tmp;

		buf1++;
		buf2++;
	}
}

int my_qsort(void* base, size_t sz, size_t width, int(*compare)(const void* p1, const void* p2))
{
	int i = 0;

	for (i = 0; i < sz - 1; i++)
	{
		int j = 0;
		for (j = 0; j < sz - 1 - i; j++)
		{
			if (compare((char*)base + j*width , (char*)base + (j+1)*width) > 0)
			{
				Swap((char*)base + j*width , (char*)base + (j + 1)*width  , width);
			}
		}
	}
}
int main()
{
	int arr[10] = { 2,6,4,7,8,9,2,5,1,3 };
	size_t sz = sizeof(arr) / sizeof(arr[0]);
	my_qsort(arr, sz , sizeof(arr[0]), compare);
	int i = 0;
	for (i = 0; i < sz; i++)
	{
		printf("%d ", arr[i]);
	}
	printf("\n");
	return 0;
}